<template>
  <div>
    <div @keyup.enter="getData()">
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.corp_name"
            placeholder="负责人查询"
            :clearable="true"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <select-address
            v-model="params.address_code"
            clearable
            placeholder="地址查询"
            :auto-top="true"
            @change="getData()"
          ></select-address>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="exportExcel(fileName)" :loading="exportLoading">导出</el-button>
        </el-form-item>
        <el-form-item class="float-right" v-if="+status === 1">
          <el-button @click="handleNew()" type="primary" icon="el-icon-plus">新增项目</el-button>
        </el-form-item>
      </el-form>
    </div>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      :height="dialogHeight"
    ></c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <approval-pass
      :visible.sync="reportVisible"
      :viewModel="viewModel"
      @success="handleEditSuccess"
      :relatedData="relatedData"
    ></approval-pass>
    <approval-refuse
      :visible.sync="refuseVisible"
      @success="handleEditSuccess"
      :relateData="relateData"
      :viewModel="viewModel"
      :queryId="queryId"
    ></approval-refuse>

    <new-project
      :visible.sync="newVisible"
      @success="handleEditSuccess"
      :customerRelatedId="relatedId"
    ></new-project>
  </div>
</template>
<script>
import { enumGuatype } from '@/credit/plugins/enumTown'

import taskTableMixin from '@/credit/mixin/task/taskTable'
import ApprovalPass from '@/credit/views/county/index/myTask/ApprovalPass'
import ApprovalRefuse from '@/credit/views/county/index/myTask/ApprovalRefuse'
import SelectAddress from '@/components/select/SelectAddress'
import NewProject from '@/credit/views/city/program/NewProject'

export default {
  components: {
    ApprovalPass,
    ApprovalRefuse,
    SelectAddress,
    NewProject,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      enumGuatype,
      order: {
        approved_date: 'desc',
      },
      params: {
        index: 1,
        size: 15,
      },
      // tableName: 'customer_related',
      totalCount: 0,
      tableData: [],
      tableColumns: [
        {
          attrs: { label: '主体名称', prop: 'customer_name', minWidth: 135 },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '地址', prop: 'address', minWidth: 135 } },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        { attrs: { label: '申请金额', prop: 'apply_funds', align: 'center' } },
        { attrs: { label: '受理机构', prop: 'service_name', minWidth: 135 } },
        { attrs: { label: '受理时间', prop: 'approved_date', align: 'center', width: 135 } },
        { attrs: { label: '业务类型', prop: 'project_type', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center', minWidth: 100 },
          operations: [
            { name: '受理', event: this.handleEdit, ifRender: row => +row.is_approval === 0 },
            {
              name: '拒绝',
              event: this.handleReject,
              attrs: { class: 'text-danger' },
              ifRender: row => +row.is_approval === 0,
            },
            { name: '受理详情', event: this.handleView, ifRender: row => +row.is_approval !== 0 },
          ],
        },
      ],

      reportVisible: false,
      relatedData: {},
      refuseVisible: false,
      queryId: '',
      relateData: {},
      viewModel: false,

      newVisible: false,
      relatedId: '',
    }
  },
  computed: {
    fileName() {
      if (+this.status === 0) {
        return '未受理项目'
      } else {
        return '已受理项目'
      }
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    handleNew(row) {
      this.newVisible = true
      this.relatedId = row ? row.customer_related_id : ''
    },
    handleView(row) {
      this.viewModel = true
      if (+row.is_approval === 2 || +row.is_approval === -1) {
        this.relateData = { ...row }
        this.refuseVisible = true
      } else {
        this.relatedData = { ...row }
        this.reportVisible = true
      }
    },
    handleReject(row) {
      this.viewModel = false
      this.refuseVisible = true
      this.queryId = row.customer_related_id
    },
    dataAdapter(item) {
      item.approved_date = this.$utils.dateFormat(item.approved_date, this.dateFmt) || '-'
      item.project_type = enumGuatype[item.gua_type] || '-'
      return item
    },
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleEdit(row) {
      this.viewModel = false
      this.relatedData = { ...row }
      this.reportVisible = true
    },
    handleEditSuccess() {
      this.$store.dispatch('getMyTaskCount')
      this.$emit('success', true)
    },
  },
}
</script>
<style lang="scss" scoped></style>
